// 获取线程通信的通道
// 用到的通信通道是tokio的
use once_cell::sync::Lazy;
use tokio::sync::Mutex;
use tokio::sync::mpsc::{channel, unbounded_channel, Receiver, Sender, UnboundedReceiver, UnboundedSender};
use std::sync::Arc;

// 用于发送手柄连接状态的通道(连接或断开)
pub static CONNECT_STATUS_CHANNEL: Lazy<(Sender<String>, Arc<Mutex<Receiver<String>>>)> = Lazy::new(|| {
    let (tx, rx) = channel(32);
    (tx, Arc::new(Mutex::new(rx)))
});

// 发送手柄摇杆数据的通道
// 不需要异步, 同步可直接调用
// L摇杆, R摇杆, L扳机, R扳机
pub static AXIS_CHANNEL: Lazy<(UnboundedSender<String>, Mutex<UnboundedReceiver<String>>)> = Lazy::new(|| {
    let (tx, rx) = unbounded_channel::<String>();
    (tx, Mutex::new(rx))
});
pub static BUTTON_CHANNEL: Lazy<(UnboundedSender<String>, Mutex<UnboundedReceiver<String>>)> = Lazy::new(|| {
    let (tx, rx) = unbounded_channel::<String>();
    (tx, Mutex::new(rx))
});
